package besuper;
import java.util.Scanner;

public class Console {

	public static Scanner sc;

	static {
		sc = new Scanner(System.in);
	}

	public static void printWelcome() {
		System.out.println("Welcome,mortal");
	}

	public static void printTips() {
		System.out.println("输入'help'获取帮助菜单");
	}

	public static void printHelp() {
		System.out.println("可供操作的命令：");
		System.out.println("list\t- 列出已有问题");
		System.out.println("ask\t- 提出新问题");
		System.out.println("answer\t- 解决已有问题");
		System.out.println("score\t- 查看分数");

	}
	public static boolean isHelp(String cmd) {
		
		return "help".equalsIgnoreCase(cmd.toUpperCase());
	}

	public static boolean isAsk(String cmd) {
		return "ask".equalsIgnoreCase(cmd);
	}

	public static boolean isAnswer(String cmd) {
		return "answer".equalsIgnoreCase(cmd);
	}

	public static boolean isList(String cmd) {
		return "list".equalsIgnoreCase(cmd);
	}
	
	private static boolean isScore(String cmd) {
		// TODO Auto-generated method stub
		return "score".equalsIgnoreCase(cmd);
	}
	
	private static boolean isExit(String cmd) {
		// TODO Auto-generated method stub
		return "exit".equalsIgnoreCase(cmd);
	}

	public static boolean printCmd(BeSuper bs) {
		boolean exit = false;
		String cmd;
		while (true) {
			System.out.print("cmd>");
			cmd = sc.nextLine();
			if (isHelp(cmd)) {
				printHelp();
				continue;
			}else if (isAsk(cmd)) {
				printAsk(bs);
				continue;
			}else if(isList(cmd)){
				Launcher.list();
			}else if(isAnswer(cmd)){
				System.out.println("请输入要解决的问题id：");
				int id = sc.nextInt();
				if(Launcher.besuper.getQuestions().isEmpty()){
					System.out.println("题库还是空的，快来添加问题吧!");
					continue;
				}
				String content = sc.nextLine();
				System.out.println("输入答案:");
				content = sc.nextLine();
				Launcher.addAns(content,id);
				
			}else if(isScore(cmd)){
				System.out.print("当前分数为: ");
				System.out.println(Launcher.besuper.getCurrentPlayer().getScore());
			}else if(isExit(cmd)){
				exit = true;
				break;
			}else if(isLogout(cmd)){
				System.out.println("已退出登录");
				break;
			}else{
				printError();
			}
		}
		return exit;
	}

	private static boolean isLogout(String cmd) {
		// TODO Auto-generated method stub
		return "logout".equalsIgnoreCase(cmd);
	}

	private static void printAsk(BeSuper bs) {
		System.out.println("请输入问题:");
		String content = sc.nextLine();
		Launcher.addQues(content);
		
	}

	private static void printError() {
		System.out.println("无效命令，请参考帮助文档：");
		printHelp();
	}
	
	public static void printName(BeSuper bs) {
		System.out.print("请输入您的名字:");
		String name = sc.nextLine();
		Launcher.signIn(name);
	}

}
